// for...of 是遍历有迭代器属性的对象

function forOf(obj, cb) {
  if (!obj[Symbol.iterator]) {
    throw new TypeError(obj + "is not iterator")
  }

  let iterator = obj[Symbol.iterator]()
  let res = iterator.next()
  while (!res.done) {
    cb(res.value)
    res = iterator.next()
  }
}

let arr = [1, 2, 3, 4]
forOf(arr, function (value) {
  console.log(value);
})